package at.sysarch.filter;

import java.awt.Rectangle;
import javax.media.jai.PlanarImage;
import at.sysarch.utils.ImageChangedEvent;
import at.sysarch.utils.ImageChangedListener;

public class ROIFilter extends AbstractListenerManager implements ImageChangedListener {

	private Rectangle _rectangle = new Rectangle(0, 50, 448, 60);
	public static PlanarImage IMAGE;
	PlanarImage _image = null;

	public void setInputImage(PlanarImage image) {
		_image = image;
		IMAGE = _image;
		updateImage();
	}

	public Rectangle getRectangle() {
		return _rectangle;
	}

	public void setRectangle(Rectangle rectangle) {
		_rectangle = rectangle;
		updateImage();
	}

	@Override
	public void imageChanged(ImageChangedEvent event) {
		setInputImage(event.getImage());
	}

	private void updateImage() {
		PlanarImage image = PlanarImage.wrapRenderedImage(_image.getAsBufferedImage(_rectangle, _image.getColorModel()));
		fireImageChanged(image);
	}
}
